package main

import (
	"fmt"
	"net/http"

	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()

	r.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message.proto": "pong",
		})
	})

	goodsRouter := r.Group("/goods")
	{
		goodsRouter.GET("", func(c *gin.Context) {
			c.JSON(http.StatusOK, gin.H{
				"list": "1231231",
			})
		})

		// 一个参数
		//goodsRouter.GET("/:id", func(c *gin.Context) {
		//	id := c.Param("id")
		//	fmt.Println("id: ", id)
		//
		//	c.JSON(http.StatusOK, gin.H{
		//		"id": id,
		//	})
		//})

		// 多个参数
		goodsRouter.GET("/:name/:age", func(c *gin.Context) {
			name := c.Param("name")
			age := c.Param("age")
			fmt.Println("name: ", name)
			fmt.Println("age: ", age)

			c.JSON(http.StatusOK, gin.H{
				"name": name,
				"age":  age,
			})
		})
	}
	r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
